home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / RTANKSRC.ZIP / BULLET.C < prev    next >
C/C++ Source or Header  |  1995-03-07  |  4KB  |  154 lines

  1. void add_hit(int x, int y);
  2. void stop_bullet(int a);
  3. /**--------------------------------------------------------------
  4.  **
  5.  **--------------------------------------------------------------
  6.  ** MODULE     : bullet.c
  7.  ** PURPOSE    : <t> bullet manager for interpreter
  8.  ** PROGRAMMER : Sandy
  9.  ** START DATE : 11/29/1988 11:55:11
  10.  ** DESCRIPTION:
  11.  **            :
  12.  **            :
  13.  **==============================================================
  14.  **/
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <dos.h>
  19. #include <conio.h>
  20. #include <string.h>
  21.  
  22. #include "dtypes.h"
  23. #include "host.h"
  24. #include "newload.h"
  25. #include "bullet.h"
  26. #include "callasm.h"
  27.  
  28. #include "tiles.h"
  29.  
  30. extern BOOL update_scr;
  31.  
  32. #define TANKSTART TANK1D8A
  33. #define isbullet(x) (((x)>=CANNONBL && (x)<TANKSTART) ? TRUE : FALSE)
  34.  
  35. int nhits;
  36. int nshots;
  37. BULLET shots[50];
  38. HITS   hits[50];
  39. int setbullet;
  40.  
  41. /*<f>----------------------------------------
  42.  * FUNCTION: <s> void init_bullet(int x, int y, int xi, int yi, int r)
  43.  * PURPOSE : Initilize a bullet to start at (x,y) and increment at
  44.  *         : (xi,yi) with a range of r units
  45.  * CREATION: 12/05/1988 19:01:53
  46.  */
  47. void init_bullet(int x, int y, int xi, int yi, int r)
  48. {
  49.    if (nshots>48) return;
  50.  
  51.    shots[nshots].bx=x;
  52.    shots[nshots].by=y;
  53.    shots[nshots].obx=x+xi;
  54.    shots[nshots].oby=y+yi;
  55.    shots[nshots].incx=xi;
  56.    shots[nshots].incy=yi;
  57.    shots[nshots].range=r;
  58.    shots[nshots].dead=FALSE;
  59.    shots[nshots].misstile=setbullet;
  60.    shots[nshots].saveunder=getmapXY(shots[nshots].obx,shots[nshots].oby);
  61.    if (isbullet(shots[nshots].saveunder))
  62.       shots[nshots].saveunder=NOTILE;
  63.  
  64.    nshots++;
  65.  
  66. } /* void init_bullet(int x, int y, int xi, int yi, int r) */
  67.  
  68. /*<f>----------------------------------------
  69.  * FUNCTION: <s> void init_bullets(void)
  70.  * PURPOSE : Initilize bullet manager
  71.  *         :
  72.  * CREATION: 12/05/1988 19:02:42
  73.  */
  74. void init_bullets(void)
  75. {
  76.    nshots=0;
  77. } /* void init_bullets(void) */
  78.  
  79. /*<f>----------------------------------------
  80.  * FUNCTION: <s> void move_bullets(void)
  81.  * PURPOSE : Move bullets around the screen
  82.  *         :
  83.  * CREATION: 12/05/1988 19:03:06
  84.  */
  85. void move_bullets(void)
  86. {
  87. int a, keep;
  88.  
  89.    nhits=0;
  90.  
  91.    for (a=0; a<nshots; a++)
  92.       if (!shots[a].dead) {
  93.  
  94.          update_scr=TRUE;
  95.  
  96.          shots[a].bx+=shots[a].incx;
  97.          shots[a].by+=shots[a].incy;
  98.          shots[a].range--;
  99.  
  100.          if (shots[a].bx<=MINPX ||
  101.              shots[a].bx>=MAXPX ||
  102.              shots[a].by<=MINPY ||
  103.              shots[a].by>=MAXPY ||
  104.              shots[a].range<1
  105.             ) {
  106.                setmapXY(shots[a].obx,shots[a].oby,shots[a].saveunder);
  107.                stop_bullet(a);
  108.                a--;
  109.          } else {
  110.             keep=getmapXY(shots[a].bx,shots[a].by);
  111.             if (isbullet(keep)) keep=NOTILE;
  112.  
  113.             setmapXY(shots[a].bx,shots[a].by,shots[a].misstile);
  114.             setmapXY(shots[a].obx,shots[a].oby,shots[a].saveunder);
  115.  
  116.             shots[a].saveunder=keep;
  117.             shots[a].obx=shots[a].bx;
  118.             shots[a].oby=shots[a].by;
  119.  
  120.             if (keep>=TANKSTART || (keep>=BRICK && keep<TANK1D8A) || keep==TRED) {    /* Hit */
  121.                if (keep<TANKSTART)
  122.                   setmapXY(shots[a].bx,shots[a].by,shots[a].saveunder);
  123.                add_hit(shots[a].bx,shots[a].by);
  124.                stop_bullet(a);
  125.                a--;
  126.             }
  127.          }
  128.       }
  129. } /* void move_bullets(void) */
  130.  
  131. /*<f>----------------------------------------
  132.  * FUNCTION: <s> void stop_bullet(int a)
  133.  * PURPOSE : Stop bullet A
  134.  *         :
  135.  * CREATION: 12/06/1988 07:42:03
  136.  */
  137. void stop_bullet(int a)
  138. {
  139.    if (a<nshots-1)
  140.       memcpy(&shots[a],&shots[nshots-1],sizeof(BULLET));
  141.    nshots--;
  142. } /* void stop_bullet(int a) */
  143.  
  144. /*<f>----------------------------------------
  145.  * FUNCTION: <s> void add_hit(int x, int y)
  146.  * PURPOSE : Add a registered hit to list
  147.  *         :
  148.  * CREATION: 01/10/1989 13:55:18
  149.  */
  150. void add_hit(int x, int y)
  151. {
  152.    hits[nhits].hx  =x;
  153.    hits[nhits++].hy=y;
  154. } /* void add_hit(int x, int y) */